﻿namespace ExamV5.WAPPage
{
    using ExamV5;
    using ExamV5.Common;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmNewsList : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected ImageButton ImgButExit;
        protected Label labNewsList;
        private PublicFun publicFun_0 = new PublicFun();

        protected void ImgButExit_Click(object sender, ImageClickEventArgs e)
        {
            base.Response.Cookies["ExamUserCode"].Value = "";
            base.Response.Cookies["ExamUserName"].Value = "";
            base.Response.Cookies["ExamDeptName"].Value = "";
            base.Response.Cookies["ExamDeptID"].Value = "";
            base.Response.Cookies["ExamWorker"].Value = "";
            base.Response.Cookies["ExamUserSex"].Value = "";
            base.Response.Cookies["ExamUserLevel"].Value = "";
            base.Response.Cookies["ExamUserGWName"].Value = "";
            base.Response.Cookies["ExamUserGWLevel"].Value = "";
            string str = base.Request.Url.ToString();
            str = str.Substring(0, str.LastIndexOf('/') + 1);
            base.Response.Redirect(str + "FrmLogin.aspx");
        }

        private void method_0()
        {
            this.labNewsList.Text = "";
            string str = "";
            string contentStr = "";
            string cmdText = ("select ID,TitleInfo,ContentInfo,InputTime,IsTopInfo=case IsTop when 'N' then '一般' when 'Y' then '置顶' end ,BrowNum from NewsInfo where TitleInfo is not null  and (BrowUserCode like '%,所有人员,%' or BrowUserCode like '%," + this.httpCookie_0.Value + ",%')") + " order by IsTop desc";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                str = reader["TitleInfo"].ToString();
                if (str.Length > 15)
                {
                    str = str.Substring(0, 15) + "…";
                }
                contentStr = CommonUtils.NoHTML(reader["ContentInfo"].ToString());
                DateTime time = DateTime.Parse(reader["InputTime"].ToString());
                //this.labNewsList.Text = this.labNewsList.Text + "<tr><td  height='40' width='31'><img src='image/TDLeft.jpg' border='0'/></td><td background='image/TDCenter.jpg' align='left'><a href='FrmShowNews.aspx?ID=" + reader["ID"].ToString() + "' onfocus='this.blur();'>" + str + "</a></td><td  width='15'><img src='image/TDRight.jpg' border='0'/></td></tr>";
                this.labNewsList.Text += $"<div class=\"new_item\"><h2 class=\"title\"><span><a href='FrmShowNews.aspx?ID={reader["ID"].ToString()}'>{str}</a></span><span class=\"time\">{time.ToShortDateString()}</span></h2><p class=\"new_summary\">{contentStr}</p></div>";
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            if (this.labNewsList.Text == "")
            {
                //this.labNewsList.Text = "<tr><td  height='40' width='31'><img src='image/TDLeft.jpg' border='0'/></td><td background='image/TDCenter.jpg' align='left'><font color=red>暂无新闻公告信息！</font></td><td  width='15'><img src='image/TDRight.jpg' border='0'/></td></tr>";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                    this.method_0();
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>window.location.href='FrmLogin.aspx';</script>");
            }
        }
    }
}

